package com.mycode.skill.HandleException;

import com.mycode.skill.commom.RestBean;
import com.mycode.skill.commom.enums.ResponseCodeEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * ValidateExceptionController
 * 参数异常处理
 * @author Qhy
 * @date 2023/12/12
 */
@ControllerAdvice
@Slf4j
public class ValidateExceptionController {

    @ResponseBody
    @ExceptionHandler(value = MethodArgumentNotValidException.class)
    public RestBean<String> handleValidateException(MethodArgumentNotValidException e){
        log.warn(e.getMessage(),e);
        return RestBean.failure(ResponseCodeEnum.EXCEPTION.value, "参数校验失败！");
    }

}
